﻿<?php

//downErWeiMa($_GET['starTime'],$_GET['endTime'],$_GET['shengFeng']);

ini_set("display_errors", "On");

downExcelAll();

function downExcelAll(){


	$qure = "SELECT title,start_date,NAME,link_url FROM youjutell WHERE NAME IN ('591-lx','test-lx') AND start_date BETWEEN '".$_GET['starDate']." 00:00:00' AND '".$_GET['endDate']." 23:59:59'";

	$host='localhost';
	$user='root';
	$password='root';
	$database='weizandata';
	$link=mysqli_connect($host, $user, $password, $database);
	$link->query("set names utf8");
	$result=mysqli_query($link, $qure);
	$arr=mysqli_fetch_all($result, 1);

	// echo '<pre>';

	// 	var_dump($arr);

	// echo '</pre>';


	// return ;

	require_once 'PHPExcel-1.8/Classes/PHPExcel.php';

	$excelFiled=array("日期","客户名称","渠道","手机号");

	//var_dump($excelFiled);

	$row=1;

	$objPHPExcel=new PHPExcel();

	$objPHPExcel->getActiveSheet()->fromArray($excelFiled,'A1');

	for($i=0;$i<count($arr);$i++){

		//$disCity=$arr['tell'][$i];

	 	$row+=1;

	 	$objPHPExcel->getActiveSheet()->setCellValue('A'.$row, $arr[$i]['title']);

	 	$objPHPExcel->getActiveSheet()->setCellValue('B'.$row,$arr[$i]['start_date']);

	 	$objPHPExcel->getActiveSheet()->setCellValue('C'.$row, $arr[$i]['NAME']);

	 	$objPHPExcel->getActiveSheet()->setCellValue('D'.$row, $arr[$i]['link_url']);


	}

		$objWriter =PHPExcel_IOFactory:: createWriter($objPHPExcel, 'Excel2007');

		$nameFile='电话导入模板'.date("Ymd");

		$objWriter->save("excel/{$nameFile}.xlsx");  // //excel/二维码.xlsx

//}


		header("Location: excel/{$nameFile}.xlsx");

}

?>